package com.demo2do.fms.scheduler.dao.fms;

import java.util.Date;
import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Update;
import com.demo2do.core.persistence.annotation.Variable;
import com.demo2do.fms.scheduler.entity.appointment.DriverCostAppointment;
import com.demo2do.fms.scheduler.entity.appointment.DriverMileageAppointment;
import com.demo2do.fms.scheduler.entity.appointment.TransportRevenueAppointment;
import com.demo2do.fms.scheduler.entity.appointment.VehicleMileageAppointment;

/**
 *
 * @author Ark
 *
 */
@Dao
public interface AppointmentDao {

    /**
     * @param status
     * @param createDate
     * @return
     */
    @Query("SELECT id, code, organization_id, begin_shipment_date, end_shipment_date, begin_reimburse_date, end_reimburse_date FROM fms_vehicle_mile_appointment WHERE is_disabled = 0 AND status = :status AND TO_CHAR(create_time, 'yyyy-mm-dd') = :createDate")
    public List<VehicleMileageAppointment> listVehicleMileage(@Variable("status") String status, @Variable("createDate") String createDate);
    
    /**
     * @param status
     * @param createDate
     * @return
     */
    @Query("SELECT id, code, organization_id, begin_shipment_date, end_shipment_date, begin_reimburse_date, end_reimburse_date, url FROM fms_vehicle_mile_appointment WHERE is_disabled = 0 AND status = :status AND create_time < :createDate")
    public List<VehicleMileageAppointment> listExpiredVehicleMileage(@Variable("status") String status, @Variable("createDate") Date createDate);
    
    /**
     * @param appointment
     */
    @Update("UPDATE fms_vehicle_mile_appointment SET status = :status, handle_time = :handleTime, finish_time = :finishTime, url = :url, reason = :reason, last_operator = :lastOperator, last_modify_time = :lastModifyTime WHERE id = :id")
    public void update(VehicleMileageAppointment appointment);
    
    /**
     * @param status
     * @return
     */
    @Query("SELECT id, code, organization_id, begin_dispatch_date, end_dispatch_date, begin_reimburse_date, end_reimburse_date FROM fms_driver_mile_appointment WHERE is_disabled = 0 AND status = :status AND TO_CHAR(create_time, 'yyyy-mm-dd') = :createDate")
    public List<DriverMileageAppointment> listDriverMileage(@Variable("status") String status, @Variable("createDate") String createDate);
    
    /**
     * @param status
     * @param createDate
     * @return
     */
    @Query("SELECT id, code, organization_id, begin_dispatch_date, end_dispatch_date, begin_reimburse_date, end_reimburse_date, url FROM fms_driver_mile_appointment WHERE is_disabled = 0 AND status = :status AND create_time < :createDate")
    public List<DriverMileageAppointment> listExpiredDriverMileage(@Variable("status") String status, @Variable("createDate") Date createDate);
    
    /**
     * @param appointment
     */
    @Update("UPDATE fms_driver_mile_appointment SET status = :status, handle_time = :handleTime, finish_time = :finishTime, url = :url, reason = :reason, last_operator = :lastOperator, last_modify_time = :lastModifyTime WHERE id = :id")
    public void update(DriverMileageAppointment appointment);
    
    /**
     * @param status
     * @return
     */
    @Query("SELECT id, code, organization_id, is_business AS business, begin_shipment_date, end_shipment_date, collect_status, is_invoice AS invoice, is_balanced AS balanced FROM fms_trans_revenue_appointment WHERE is_disabled = 0 AND status = :status AND TO_CHAR(create_time, 'yyyy-mm-dd') = :createDate")
    public List<TransportRevenueAppointment> listTransportRevenue(@Variable("status") String status, @Variable("createDate") String createDate);
    
    /**
     * @param status
     * @param createDate
     * @return
     */
    @Query("SELECT id, code, organization_id, is_business AS business, begin_shipment_date, end_shipment_date, collect_status, is_invoice AS invoice, is_balanced AS balanced, url FROM fms_trans_revenue_appointment WHERE is_disabled = 0 AND status = :status AND create_time < :createDate")
    public List<TransportRevenueAppointment> listExpiredTransportRevenue(@Variable("status") String status, @Variable("createDate") Date createDate);
    
    /**
     * @param appointment
     */
    @Update("UPDATE fms_trans_revenue_appointment SET status = :status, handle_time = :handleTime, finish_time = :finishTime, url = :url, reason = :reason, last_operator = :lastOperator, last_modify_time = :lastModifyTime WHERE id = :id")
    public void update(TransportRevenueAppointment appointment);
    
    /**
     * @param status
     * @return
     */
    @Query("SELECT id, code, organization_id, begin_reimburse_date, end_reimburse_date FROM fms_driver_cost_appointment WHERE is_disabled = 0 AND status = :status AND TO_CHAR(create_time, 'yyyy-mm-dd') = :createDate")
    public List<DriverCostAppointment> listDriverCost(@Variable("status") String status, @Variable("createDate") String createDate);
    
    /**
     * @param status
     * @param createDate
     * @return
     */
    @Query("SELECT id, code, organization_id, begin_reimburse_date, end_reimburse_date, url FROM fms_driver_cost_appointment WHERE is_disabled = 0 AND status = :status AND create_time < :createDate")
    public List<DriverCostAppointment> listExpiredDriverCost(@Variable("status") String status, @Variable("createDate") Date createDate);
    
    /**
     * @param appointment
     */
    @Update("UPDATE fms_driver_cost_appointment SET status = :status, handle_time = :handleTime, finish_time = :finishTime, url = :url, reason = :reason, last_operator = :lastOperator, last_modify_time = :lastModifyTime WHERE id = :id")
    public void update(DriverCostAppointment appointment);
    
}
